Skip to content

diff: skip the diff for identical contents - #440

Merged
sylvestre merged 2 commits into
uutils:mainfrom
KrushnXGIT:diff-skip-identical-contents
Nov 28, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
KrushnXGIT:diff-skip-identical-contents

Conversation

@KrushnXGIT

Copy link
Copy Markdown
Contributor

Text files always went through the diff algorithm, even when both had the same contents; only binary files were compared first. This compares the contents first for text too.

Side by side output and ed scripts still go through the diff: -y prints the lines, and -e warns about a missing newline even for equal files (missing_newline_ed::case_5_same_content).

diff -r on two copies of coreutils/src (877 files), hyperfine 15 runs:

GNU 3.10 main this PR
identical trees 11.8 ms 45.6 ms 31.8 ms
300 files changed 13.5 ms 46.2 ms 38.9 ms

Two identical 400k-line files: peak memory 50 MB -> 9 MB. Output, stderr and exit code are the same as main in 64 cases (all formats, -s, -q, -N, stdin, binary, -r).

Text files always went through the diff algorithm, even when both had the same contents. Compare the contents first, as was already done for binary files. Side by side output and ed scripts still go through it: the first shows the lines, the second warns about a missing newline.
Comment thread src/diff.rs Resolved
@sylvestre
sylvestre merged commit 4885ea9 into uutils:main Nov 28, 2026
31 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants